<template>
  <div class="cartcontrol">
    <scroll-animation>
      <div class="cart-decrease" v-show="food.count>0" @click.stop.prevent="decreaseCart">
          <span class="inner iconfont icon-remove_circle_outline">&#xe693;</span>
      </div>
    </scroll-animation>
    <div class="cart-count" v-show="food.count>0">{{food.count}}</div>
    <div ref="cartAddDom" class="cart-add iconfont icon-add_circle" @click.stop.prevent="addCart">&#xe60d;</div>
  </div>
</template>

<script>
  import Vue from 'vue'
  import ScrollAnimation from "../fade/ScrollAnimation"
    export default {
        name: "CartControl",
        components: {
          ScrollAnimation
        },
        props: {
          food: Object
        },
        methods: {
          addCart (event) {
            if (!event._constructed) {
              return
            }
            if (!this.food.count) {
              Vue.set(this.food, 'count', 1)
            } else {
              this.food.count++
            }
            this.$emit('cartAdd', this.$refs.cartAddDom)
          },
          decreaseCart (event) {
            if (!event._constructed) {
              return
            }
            if (this.food.count) {
              this.food.count--
            }
          }
        }
    }
</script>

<style lang="stylus" scoped>
  .cartcontrol
    font-size: 0
    .cart-decrease
      display: inline-block
      padding: 6px
      .inner
        display: inline-block
        line-height: 24px
        font-size: 24px
        color: rgb(0, 160, 220)
    .cart-count
      display: inline-block
      vertical-align: top
      width: 12px
      padding-top: 6px
      line-height: 24px
      text-align: center
      font-size: 10px
      color: rgb(147, 153, 159)
    .cart-add
      display: inline-block
      padding: 6px
      line-height: 24px
      font-size: 24px
      color: rgb(0, 160, 220)

</style>
